package forum.controller;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import forum.*;
import forum.wrapper.WrapRequest;

/**
 *  Dispatcher
 *
 *@author     Ivan
 *@created    2010年6月22日
 */
public class Dispatcher extends HttpServlet {	

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			 throws ServletException, IOException {
		try {
			String url = request.getRequestURI();

            String sub_url = url.substring(url.lastIndexOf("/") + 1);
			
			WrapRequest req = new WrapRequest(request);
			
			String to = "";

            if(sub_url.split("\\.").length==2){
                String[] temp = sub_url.split("\\.");
                String cls = "forum.service." + temp[0];
                Class obj = Class.forName(cls);
                to = (String) obj.getDeclaredMethod(temp[1],WrapRequest.class).invoke(obj.newInstance(),req);
            }
			
			response.sendRedirect(Variable.getForumPath() + to);
		} catch (Exception e) {
			
		}
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
	 throws ServletException, IOException {
		doPost(request, response);
	}
}

